package cn.lf.android.lawfirm.upgrade.approval;

import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.lf.android.lawfirm.BaseActivity;
import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.downloadcontroller.modle.Agreement;
import cn.lf.android.lawfirm.downloadcontroller.view.AgreementAdapter;
import cn.lf.android.lawfirm.undertake.approval.modle.CaseDetail;
import cn.lf.android.lawfirm.undertake.approval.modle.Summary;
import cn.lf.android.lawfirm.upgrade.approval.controler.UpgradeCaseDetailController;
import cn.lf.android.lawfirm.utils.DebugLog;

public class CaseDetailActivity extends BaseActivity implements UpgradeCaseDetailController.CaseDetailCallback {

    /**
     * 返回
     **/
    private ImageButton img_left;
    /**
     * 标题
     **/
    private TextView mtitle;
    /**
     * 审级
     **/
    private TextView trial_level;
    /**
     * 合同
     **/
    private ListView mListView;
    private AgreementAdapter mAgreementAdapter;
    private List<Agreement> mList = new ArrayList<Agreement>();
    /**
     * 名称
     **/
    private TextView tv_name;
    /**
     * 申请人
     **/
    private TextView applicant;
    /**
     * 承办团队
     **/
    private TextView team;
    private UpgradeCaseDetailController mCaseDetailController;
    private String caseID = "";
    Summary mBean;

    @Override
    public Object getContentResView() {
        return R.layout.activity_case_detail;
    }

    @Override
    public void initView() {
        initTitle();
        caseID = getIntent().getStringExtra("caseID");
        mBean = (Summary) getIntent().getSerializableExtra("bean");
        trial_level = (TextView) findViewById(R.id.trial_level);
        tv_name = (TextView) findViewById(R.id.name);
        applicant = (TextView) findViewById(R.id.applicant);
        team = (TextView) findViewById(R.id.team);
        mListView = (ListView) findViewById(R.id.file_list);
        mAgreementAdapter = new AgreementAdapter(this, mList);
        mListView.setAdapter(mAgreementAdapter);
    }


    private void initTitle() {
        img_left = (ImageButton) findViewById(R.id.img_left);
        img_left.setVisibility(View.VISIBLE);
        img_left.setOnClickListener(this);
        mtitle = (TextView) findViewById(R.id.eb_tv_title);
        mtitle.setVisibility(View.VISIBLE);
        mtitle.setText("案件详情");
    }

    @Override
    public void initData() {
        //滑动退出
//        addSwipeFinishLayout();
        mCaseDetailController = new UpgradeCaseDetailController(this, this);
        mCaseDetailController.onCaseDetail(caseID, mBean.levelID);
        DebugLog.e("承办详情==" + mBean.attachments);
        mList.addAll(mBean.attachments);
        mAgreementAdapter.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_left:
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }

    @Override
    public void onCaseDetailuccessed(CaseDetail beans) {
        tv_name.setText(beans.caseName);
        trial_level.setText(beans.levelName);
        applicant.setText(mBean.userName);
        team.setText(beans.members);
    }

    @Override
    public void onCaseDetailFailed() {

    }
}
